﻿
@{
    ViewBag.Title = "患者切换";
    Layout = "~/Views/Shared/_Form.cshtml";
    var from = (ViewBag.from as string) ?? "";
}
<style>
    .table-responsive {
        border: 0;
    }

    .ui-jqgrid .ui-jqgrid-pager .ui-pager-table {
        width: 90%;
    }
</style>

<div class="topPanel" style="border-bottom:1px solid rgb(221, 221, 221);margin-bottom: 1%;">
    <div class="search">
        <table class="form">
            <tr>
                <th class="formTitle">病历号/姓名：</th>
                <td class="formValue" colspan="2">
                    <input id="txt_keyword" name="txt_keyword" type="text" class="form-control form-an" placeholder="请输入病历号/姓名/首拼" />
                </td>
                <th class="formTitle">门诊号：</th>
                <td class="formValue">
                    <input id="txt_mzh" name="txt_mzh" type="text" class="form-control form-an" placeholder="请输入门诊号" />
                </td>
                <th class="formTitle">住院号：</th>
                <td class="formValue">
                    <input id="txt_zyh" name="txt_zyh" type="text" class="form-control form-an" placeholder="请输入住院号" />
                </td>
                @*<th class="formTitle">姓名：</th>
                <td class="formValue">
                    <input id="txt_xm" name="txt_xm" type="text" class="form-control form-an form-an-end" placeholder="请输入姓名或首拼" />
                </td>*@
                <td style="padding-left: 20px;">
                    <button type="button" id="btn_search" class="btn btn-primary btn-md">&nbsp;查询&nbsp;</button>
                </td>
            </tr>
            <tr>

            </tr>
        </table>
    </div>
</div>
<!--患者信息 包括病历号  姓名 -->
<form id="formPatSer" style="margin:2px;margin-top:10px;">
    <div class="gridPanel">
        <table id="patGridList" rel="formPatSer"></table>
        <div id="gridPagerpat" style="padding-right:20%"></div>
    </div>
</form>

<script>
    var ywlx = $.request("ywlx");
    var zyh = "";
    var mzh = "";
    //上一个window对象
    var prevWindow;
    var patcenter;
    if ('@(from)' !== '') {
        prevWindow = top.top.frames['@(from)'];
    }
    else {
        prevWindow = $.currentWindow();
    }

    $(function () {

        var obj = new Object;
        obj.blh = $.request("blh");
        obj.ywlx = ywlx;
        var searInfo = new PatSearchInfo();
        //加载数据
        searInfo.init(obj);

        //$('#txt_xm').keyupEnterEvent(function () {
        //    $('#btn_search').trigger('click');
        //});
        if (ywlx == "zy") {
            zyh = $("#txt_zyh").val();
        }
        getPatientlist();
        //查询
        $("#btn_search").click(function () {
            getPatientlist();
            //$("#patGridList").jqGrid('setGridParam', {
            //    postData: getPostdata(),
            //    page: 1,
            //    url: "/PatientManage/PatientCenter/PatSearchInfo"
            //}).trigger('reloadGrid');
        });
    });
    var PatSearchInfo = (function () {
        //加载列表
        var loadGrid = function (data) {
            var $gridList = $("#patGridList");
            $gridList.dataGrid({
                datatype: 'local',
                altRows: true,
                height: $(window).height() - 200,
                autowidth: false,
                width: $("#formPatSer").width() - 10,
                //url: "/PatientManage/PatientCenter/PatSearchInfo",
                postData: getPostdata(),
                caption: '患者信息列表',
                colModel: [
                    { label: '主键', name: 'patid', hidden: true, key: true },
                    { label: '病历号', name: 'blh', width: 60, align: 'center' },
                    { label: '住院号', name: 'zyh', width: 60, align: 'center' },
                    { label: '病人性质', name: 'brxzmc', width: 60, align: 'center' },
                    {
                        label: '状态', name: 'zybz', width: 60, align: 'center', formatter: function (cellvalue) {
                            return $.enum.getDescByValue("EnumZYBZ", cellvalue);
                        }
                    },
                    { label: '姓名', name: 'xm', width: 120, align: 'left' },
                    { label: '出生年月', name: 'csny', hidden: true, width: 120, align: 'center' },
                    {
                        label: '性别', name: 'xb', width: 70, align: 'left', formatter: function (cellvalue) {
                            return $.getGender(cellvalue);
                        }
                    },
                    {
                        label: '年龄', name: 'nlshow', width: 50, align: 'center'
                    },
                    { label: '证件号', name: 'zjh', width: 100, align: 'left' },
                     { label: '', name: 'CreateTime', hidden: true }
                ],
                pager: "#gridPagerpat",
                sortname: 'CreateTime desc',
                viewrecords: true,
                rowNum: 1000,
                rowList: [1000]
            });

            
        };

        var myPatSearchInfo = function (data) {

        }

        //加载事件
        myPatSearchInfo.prototype.init = function (data) {
            if (data.blh === "null") {
                $("#txt_blh").val("");
            } else {
                $("#txt_blh").val(data.blh);
            }
            loadGrid(data);
        };
        return myPatSearchInfo;
    }());

    //jqGrid 双击选中某行
    function btn_edit() {
        PatSearchConfirm();
    }

    function PatDbGrid() {
        var $gridList = $("#patGridList");
        var blh = $gridList.jqGridRowValue().blh;
        var obj = new Object();
        obj.blh = blh;
        obj.zyh = $gridList.jqGridRowValue().zyh;
        obj.nlshow = $gridList.jqGridRowValue().nlshow;
        obj.xm = $gridList.jqGridRowValue().xm;
        obj.patid = $gridList.jqGridRowValue().patid;
        obj.startTime = $.currentWindow().$("#ks").val();
        obj.endTime = $.currentWindow().$("#js").val();
        var pat = patcenter.find(p => p.zyh == obj.zyh);
        prevWindow.GetPatQueryAjax(pat);
        //关闭窗口
        ReceiptCancle();
    }
    //确定 主页面调用
    function PatSearchConfirm() {
        PatDbGrid();
    }

    //取消
    function ReceiptCancle() {
        $.modalClose();
    }

    function getPostdata() {
        var zyh = "";
        var mzh = "";
        if (ywlx == "zy") {
            zyh = $("#txt_zyh").val();
        }
        else if (ywlx == "mz") {
            mzh = $("#txt_mzh").val();
        }
        return { blh: $("#txt_blh").val(), keyword: $("#txt_keyword").val(), mzh: mzh, zyh: zyh, ywlx: ywlx };
    }

    function getPatientlist()
    {
        $.najax({
            url: "/PatientManage/PatientCenter/PatSearchInfo",
            data: getPostdata(),
            dataType: "json",
            async: false,
            success: function (data) {
                patcenter = data.rows;
                var reader = {
                    root: function (obj) { return data.rows; },
                    page: function (obj) { return data.page; },
                    total: function (obj) { return data.total; },
                    records: function (obj) { return data.records; }
                }
                $("#patGridList").setGridParam({ data: data.zyinfolist, localReader: reader }).trigger('reloadGrid');
            }
        });
    }
</script>



